package com.example.ywj.toutiao.utils;


import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import com.bumptech.glide.request.RequestOptions;
import com.example.ywj.toutiao.R;
import com.example.ywj.toutiao.bean.SVideo;
import com.example.ywj.toutiao.bean.Video;
import com.example.ywj.toutiao.compoents.JZ;

import java.util.List;

import cn.jzvd.JZVideoPlayer;
import cn.jzvd.JZVideoPlayerStandard;


public class MySVideoBaseAdapter extends BaseAdapter {
    private static final String TAG = "MyBaseAdapter";
    private List<SVideo> list ;
    private String baseUrl = Constant.BASEURL;
    private String videoBaseUrl = Constant.VIDEOBASEURL;
    public MySVideoBaseAdapter(List<SVideo> list){
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            convertView = inflater.inflate(R.layout.svideo_item_layout,null);
            viewHolder = new ViewHolder();
            viewHolder.jz = convertView.findViewById(R.id.videoplayer_svideo);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        RequestOptions requestOptions = new RequestOptions();
        requestOptions.placeholder(R.drawable.placeholder).error(R.drawable.error_img);
        String imgUrl2 = baseUrl+"public/images/"+list.get(position).getImage()+".jpg";
        String videoUrl = videoBaseUrl+list.get(position).getContent()+".mp4";
        viewHolder.jz.setUp(videoUrl,JZVideoPlayerStandard.SCREEN_WINDOW_NORMAL,list.get(position).getTitle());
        viewHolder.jz.progressBar.setVisibility(View.INVISIBLE);
        viewHolder.jz.currentTimeTextView.setVisibility(View.INVISIBLE);
        viewHolder.jz.totalTimeTextView.setVisibility(View.INVISIBLE);
        Glide.with(parent.getContext()).load(imgUrl2).apply(requestOptions).into(viewHolder.jz.thumbImageView);
        viewHolder.jz.thumbImageView.setScaleType(ImageView.ScaleType.FIT_XY);
        //viewHolder.jzVideoPlayer.setVideoImageDisplayType(JZVideoPlayer.VIDEO_IMAGE_DISPLAY_TYPE_FILL_PARENT);
        return convertView;
    }
    class ViewHolder{
        JZ jz;
    }
}

